<template>
	<view class="content">
		<!-- <view class="search-block block">
			<CustomNav :isBack="true" :keyword="keyword" :custom="custom"></CustomNav>
		</view> -->
		<view class="block screen-block">
			<view class="screen-item">
				<picker :range="category" @change="bindCategory" range-key="snackName" class="picker category">
					{{category[categoryActive].snackName?category[categoryActive].snackName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
			<view class="screen-item">
				<picker :range="businessArea" @change="bindBusinessArea" range-key="shoppingName"
					class="picker businessArea">
					{{businessArea[businessAreaActive].shoppingName?businessArea[businessAreaActive].shoppingName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
			<!-- <view class="screen-item">
				<view :class="optionActive==1?'active':''" @click="bindOption(1)" class="option">离我最近</view>
			</view>
			<view class="screen-item">
				<view :class="optionActive==2?'active':''" @click="bindOption(2)" class="option">好评优先</view>
			</view> -->
		</view>
		<view class="block list-block">
			<navigator hover-class="none" :url="'/pages/food/detail?id='+item.id" v-for="(item,index) in list"
				:key="item.id" class="list-item">
				<view class="infob-block">
					<image :src="item.picUrl" mode="aspectFill" class="photo"></image>
					<view class="info">
						<view class="name">{{item.title}}</view>
						<view class="score-block">
							<view class="score-name">评分:</view>
							<view class="score">{{item.score}}</view>
							<view class="capite">￥{{item.pricePer}}</view>
							<!-- <view class="selling-season">季售{{item.sale}}</view> -->
						</view>
						<!-- <view class="category-block">
							<view class="category"> {{item.description}}</view>
							<view class="position">
								<view class="iconfont icon-dingweixiao"></view>{{item.distance}}km
							</view>
						</view> -->
						<view class="ranking-block">
							<view class="ranking">酒泉人气排行第{{item.viewList}}名</view>
						</view>
					</view>
				</view>
				<view class="goods-block">
					<view v-for="(item1,index1) in item.goods" :key="item1.id" class="goods-item">
						<view class="discount-prices">￥{{item1.discountPrices}}</view>
						<view class="original-price">￥{{item1.originalPrice}}</view>
						<view class="name">{{item1.name}}</view>
					</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		getAllSnackOd,
		getFindAllSnackLikes,
		getViewListApi,
		getShoppingListApi,
	} from '@/api/food.js';
	export default {
		data() {
			return {
				keyword: '',
				custom: null,
				category: [],
				categoryActive: 0,
				businessArea: [],
				businessAreaActive: 0,
				optionActive: 0,
				categoryActiveId: 0,
				businessAreaActiveId: 0,
				list: []
			}
		},
		methods: {
			bindCategory(e) {
				this.categoryActive = e.detail.value;
				this.findAllByList();
			},
			bindBusinessArea(e) {
				console.log(e);
				this.businessAreaActive = e.detail.value;
				this.findAllByList();
			},
			// bindOption(index) {
			// 	this.optionActive = index;
			// 	this.findAllByList()
			// },

			findAllByList() {
				if (this.category != null && this.category.length > 0) {
					this.categoryActiveId = this.category[this.categoryActive].id;
				}
				if (this.businessArea != null && this.businessArea.length > 0) {
					this.businessAreaActiveId = this.businessArea[this.businessAreaActive].id;
				}
				getAllSnackOd({
					snackType: this.categoryActiveId,
					shopping: this.businessAreaActiveId,
					orderByType: this.optionActive,
				}).then((res) => {
					if (res.code == 1) {
						if (res.info != null) {
							this.list = res.info;
							console.log(this.list)
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			//查询全部分类
			getViewList() {
				getViewListApi().then((res) => {
					if (res.code == 1) {
						this.category = res.data;
						this.categoryActive = 0;
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败',
						mask: true,
					})
				})
			},
			//商圈类型
			getShoppingList() {
				getShoppingListApi({}).then((res) => {
					if (res.code == 1) {
						this.businessArea = res.data;
						this.businessAreaActive = 0;
						this.findAllByList();
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					console.log(res)
				})
			},
			//模糊查询
			getSearchList() {
				let title = this.title
				getFindAllSnackLikes({
					title
				}).then((res) => {
					if (res.code === 1) {
						this.list = res.data;
						console.log(this.list)
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
		},
		mounted(e) {
			/*自适应微信胶囊按钮*/
			this.custom = this.utils.getCustomNavData();
		},
		onLoad() {
			uni.$on('getSearchInput', (e) => {
				this.title = e;
				this.getSearchList()
			})
			this.getViewList();
			this.getShoppingList();
		}
	}
</script>

<style lang="scss">
	.content {
		background: #F4F4F4;
		min-height: 100vh;

		.block.search-block {
			background: $color-primary;
			overflow: hidden;
		}

		.block.screen-block {
			display: flex;
			flex-direction: row;
			background: $color-primary;
			align-items: center;
			padding: 20rpx;

			.screen-item {
				display: flex;
				justify-content: center;
				color: $color-border-lighter;
				align-items: center;
				font-size: 30rpx;
				flex-grow: 1;

				.picker {
					display: flex;
					justify-content: center;
				}

				.picker.category {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.picker.businessArea {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.iconfont {
					margin-left: 16rpx;
					font-size: 28rpx;
					font-weight: normal;
				}

				.option.active {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}
			}
		}

		.block.list-block {
			display: flex;
			flex-direction: column;
			padding: 16rpx;

			.list-item {
				display: flex;
				flex-direction: column;
				padding: 20rpx;
				padding-bottom: 0;
				margin-bottom: 16rpx;
				border-radius: 20rpx;
				background: #fff;

				.infob-block {
					display: flex;
					flex-direction: row;

					.photo {
						width: 160rpx;
						height: 160rpx;
						border-radius: 10rpx;
						margin-right: 30rpx;
					}

					.info {
						width: calc(100% - 180rpx);
						display: flex;
						flex-direction: column;
						padding-bottom: 10rpx;
						// border-bottom: 1px solid #efefef;

						.name {
							font-size: 34rpx;
							font-weight: bold;
						}

						.score-block {
							display: flex;
							align-items: center;
							margin-top: 10rpx;

							.score {
								flex-grow: 0;
								font-size: 34rpx;
								font-weight: bold;
								margin-right: 14rpx;
								background: url('@/static/bottom.png') no-repeat;
								background-position: center 85%;
								background-size: 80%;
							}

							.capite {
								flex-grow: 0;
								font-size: 26rpx;
								color: $color-secondary-text;
							}

							.selling-season {
								flex-grow: 1;
								font-size: 26rpx;
								color: $color-secondary-text;
								text-align: right;
							}
						}

						.category-block {
							display: flex;
							align-items: center;
							font-size: 24rpx;
							color: $color-secondary-text;
							margin-top: 4rpx;

							.category {
								flex-grow: 0;
								margin-right: 10rpx;
							}

							.business-area {
								flex-grow: 0;
							}

							.position {
								flex-grow: 1;
								display: flex;
								flex-direction: row;
								align-items: center;
								justify-content: flex-end;

								.iconfont {
									margin-right: 10rpx;
								}
							}
						}

						.ranking-block {
							display: flex;
							margin-top: 16rpx;

							.ranking {
								font-size: 24rpx;
								background: #FCF5E1;
								color: #dba81c;
								padding: 0 4rpx;
								border-radius: 8rpx;
							}
						}
					}
				}

				.goods-block {
					width: calc(100% - 170rpx);
					margin-left: 170rpx;
					display: flex;
					flex-direction: column;
					padding: 16rpx 0;

					.goods-item {
						display: flex;
						flex-direction: row;
						align-items: center;
						font-size: 28rpx;
						margin-bottom: 10rpx;

						.discount-prices {
							color: $color-danger;
							margin-right: 10rpx;
							font-weight: bold;
							flex-grow: 0;
						}

						.original-price {
							flex-grow: 0;
							color: $color-secondary-text;
							text-decoration: line-through;
							margin-right: 20rpx;
							font-size: 26rpx;
						}

						.name {
							flex-grow: 1;
							font-weight: bold;
						}
					}

					.goods-item:last-child {
						margin-bottom: 0;
					}
				}
			}

			.list-item:last-child {
				margin-bottom: 0;
			}
		}
	}
</style>